package middlewares

import (
	"github.com/gin-contrib/sessions"

	"github.com/gin-gonic/gin"
)

func AuthRequired() gin.HandlerFunc {
	return func(c *gin.Context) {
		session := sessions.Default(c)
		if auth := session.Get("authenticated"); auth == nil || auth.(bool) != true {
			c.Redirect(302, "/login")
			c.Abort()
			return
		}
		c.Next()
	}
}
